package com.qianxx.viewlibrary.recyclerview.refreshview.internal;

import android.content.Context;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.qianxx.viewlibrary.recyclerview.refreshview.DisplayUtil;

public class SimpleLoadMoreView implements ILoadMoreView {

    private TextView mTextView;
    private boolean mHideLoadMoreText;
    private String mDefaultText = "上拉加载更多";
    private String mLoadingText = "加载中...";
    private String mLoadCompletedText = "加载完成";
    private String mHasNoMoreDataText = "没有更多了";
    private Context mContext;

    public SimpleLoadMoreView(Context context) {
        this.mContext = context;
        mTextView = new TextView(context);
        mTextView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
            @Override
            public void onViewAttachedToWindow(View v) {
                ViewGroup.LayoutParams params = mTextView.getLayoutParams();
                params.height = DisplayUtil.dp2px(mContext, 48);
                params.width = ViewGroup.LayoutParams.MATCH_PARENT;
                mTextView.setGravity(Gravity.CENTER);
                mTextView.setLayoutParams(params);
                mTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
            }

            @Override
            public void onViewDetachedFromWindow(View v) {

            }
        });

    }

    @Override
    public View getLoadMoreView() {
        return mTextView;
    }

    @Override
    public void initView() {
        String str = mHideLoadMoreText ? "" : getDefaultText();
        mTextView.setText(str);
    }

    @Override
    public void onLoading() {
        String str = mHideLoadMoreText ? "" : getLoadingText();
        mTextView.setText(str);
    }

    @Override
    public void loadCompleted() {
        String str = mHideLoadMoreText ? "" : getLoadCompletedText();
        mTextView.setText(str);
    }

    @Override
    public void hasNoMoreData() {
        String str = mHideLoadMoreText ? "" : getHasNoMoreDataText();
        mTextView.setText(str);
    }

    @Override
    public void setHideLoadMoreText(boolean hideLoadMoreText) {
        mHideLoadMoreText = hideLoadMoreText;
    }

    public String getDefaultText() {
        return mDefaultText;
    }

    public void setDefaultText(String defaultText) {
        this.mDefaultText = defaultText;
    }

    public String getLoadingText() {
        return mLoadingText;
    }

    public void setLoadingText(String mLoadingText) {
        this.mLoadingText = mLoadingText;
    }

    public String getLoadCompletedText() {
        return mLoadCompletedText;
    }

    public void setLoadCompletedText(String mLoadCompletedText) {
        this.mLoadCompletedText = mLoadCompletedText;
    }

    public String getHasNoMoreDataText() {
        return mHasNoMoreDataText;
    }

    public void setHasNoMoreDataText(String mHasNoMoreDataText) {
        this.mHasNoMoreDataText = mHasNoMoreDataText;
    }

}
